package design.create_factory;

import org.junit.Test;

/**
 * 抽象工厂
 */
public class DemoAbstractFacotry {
    @Test
    public void test() {
        Facotry facotry = new HuaWeiFactory(); //华为工厂生产出来的都是华为的产品
        facotry.createPhone().welcome();
        facotry.createNoteBook().welcome();
        facotry = new XiaoMiFactory(); //小米工厂生产出来的都是小米的产品
        facotry.createPhone().welcome();
        facotry.createNoteBook().welcome();
    }

    public interface Facotry{
        Phone createPhone();
        NoteBook createNoteBook();
    }
    //华为工厂（同一工厂生产同一系列的产品）
    public class HuaWeiFactory implements Facotry{
        @Override
        public Phone createPhone() {
            return new HuaWeiPhone();
        }
        @Override
        public NoteBook createNoteBook() {
            return new HuaWeiNoteBook();
        }
    }
    //小米工厂
    public class XiaoMiFactory implements Facotry{
        public Phone createPhone() {
            return new XiaoMiPhone();
        }
        @Override
        public NoteBook createNoteBook() {
            return new XiaoMiNoteBook();
        }
    }


}
